<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
  <th:block th:include="include :: header('用户分配项目')" />
</head>
<body>
<div class="main-content">
  <form id="form-user-add" class="form-horizontal">
    <input type="hidden" id="userId" name="userId" th:value="${user.userId}">
    <h4 class="form-header h4">基本信息</h4>
    <div class="row">
      <div class="col-sm-6">
        <div class="form-group">
          <label class="col-sm-4 control-label is-required">用户名称：</label>
          <div class="col-sm-8">
            <input name="userName" class="form-control" type="text" disabled th:value="${user.userName}">
          </div>
        </div>
      </div>
      <div class="col-sm-6">
        <div class="form-group">
          <label class="col-sm-4 control-label is-required">登录账号：</label>
          <div class="col-sm-8">
            <input name="loginName" class="form-control" type="text" disabled th:value="${user.loginName}">
          </div>
        </div>
      </div>
    </div>

    <h4 class="form-header h4">分配项目</h4>
    <div class="row">
      <div class="col-sm-12">
        <div class="col-sm-12 select-table table-striped">
          <table id="bootstrap-table"></table>
        </div>
      </div>
    </div>
  </form>
</div>

<div class="row">
  <div class="col-sm-offset-5 col-sm-10">
    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
    <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
  </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
  var prefix = ctx + "system/user/authProject";
  var projects = [[${projects}]]

  $(function() {
    var options = {
      data: projects,
      sidePagination: "client",
      sortName: "projectSort",
      showSearch: false,
      showRefresh: false,
      showToggle: false,
      showColumns: false,
      clickToSelect: true,
      maintainSelected: true,
      columns: [{
        checkbox: true,
        formatter:function (value, row, index) {
          if($.common.isEmpty(value)) {
            return { checked: row.flag };
          } else {
            return { checked: value }
          }
        }
      },
        {
          field: 'projectId',
          title: '项目编号'
        },
        {
          field: 'projectSort',
          title: '排序',
          sortable: true,
          visible: false
        },
        {
          field: 'projectName',
          title: '项目名称'
        },
        {
          field: 'createTime',
          title: '创建时间',
          sortable: true
        }]
    };
    $.table.init(options);
  });

  /* 添加项目-提交 */
  function submitHandler(index, layero){
    var rows = $.table.selectFirstColumns();
    var data = { "userId": $("#userId").val(), "projectIds": rows.join() };
    $.operate.saveTab(prefix + "/insertAuthProject", data);
  }
</script>
</body>
</html>